package de.toolschmied.jjas.client.cms;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;

import de.toolschmied.jjas.shared.TextContent;

public class TextView extends Composite {

	public static final String TITLE_STYLE = "text-title";
	public static final String BODY_STYLE = "text-body";
	
	private final FlowPanel panel = new FlowPanel();
	private final HTML titleLabel = new HTML();
	private final HTML bodyLabel = new HTML();
	
	private final TextContent content;
	
	public TextView(TextContent content) {
		this.content = content;

		init();
		update();
	}
	
	private void init() {
		titleLabel.setStylePrimaryName(TITLE_STYLE);
		bodyLabel.setStylePrimaryName(BODY_STYLE);
		
		panel.add(titleLabel);
		panel.add(bodyLabel);
		
		initWidget(panel);
	}
	
	public void update() {
		setTitle(content.getTitle());
		setBody(content.getHTML());
	}
	
	public void setTitle(String title) {
		title = "<h1>" + title + "</h1>";
		titleLabel.setHTML(title);
	}
	
	public void setBody(String html) {
		bodyLabel.setHTML(html);
	}
	
}
